package com.example.kugou.controller;

import com.example.kugou.common.time.TimeAdd;
import com.example.kugou.pojo.Song_sheet;
import com.example.kugou.service.Song_sheetService;
import com.example.kugou.vo.Song_sheetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/song")
@Api(tags = "歌单的相关方法", description = "提供歌单相关的Rest API")
public class Song_sheetController {


    @Resource
    Song_sheetService song_sheetService;

    public Song_sheetService getSong_sheetService() {
        return song_sheetService;
    }

    public void setSong_sheetService(Song_sheetService song_sheetService) {
        this.song_sheetService = song_sheetService;
    }

    @GetMapping("/selectSong")
    @ApiOperation("查看前8个歌单")
    public Map<String, Object> selectSong() {
        return song_sheetService.SeletFirstTwothSong_Sheet();
    }

    @GetMapping("/selectSong_SheetPerson")
    @ApiOperation("查询该用户的歌单")
    public Map<String, Object> selectSong_SheetPerson(int person) {
        return song_sheetService.selectSong_SheetPerson(person);
    }



    @GetMapping("/selectAllSong")
    @ApiOperation("查看所有歌单")
    public Map<String, Object> selectAllSong(@RequestParam(defaultValue = "1", value = "pageIndex") Integer pageIndex) {
        return song_sheetService.SeletAllSong_Sheet(pageIndex);
    }


    @GetMapping("/selectById")
    @ApiOperation("查看歌单信息")
    public Map<String, Object> SelectById(int ssid) {
        return song_sheetService.SelectById(ssid);
    }

    @PostMapping("/selectSongById")
    @ApiOperation("查看指定类别歌单")
    public Map<String, Object> selectSongById(int type) {
        return song_sheetService.SelectSong_SheetByShtid(type);
    }




    @PostMapping(value = "/addSong_sheet", produces = "application/json;charset=UTF-8")
    @ApiOperation("添加歌单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ssname",value="用户账号",required = false),
            @ApiImplicitParam(name = "person",value="用户密码",required = false),
    })
    public Song_sheetVO add(String ssname,int person) {
        System.out.println("进入");
        String time02 = TimeAdd.getTime02();
        Song_sheetVO song_sheetVO = new Song_sheetVO();
        int i = song_sheetService.addSong_sheet(ssname, person,time02);
        if (i > 0) {
            song_sheetVO.setStatus(true);
        } else {
            song_sheetVO.setStatus(false);
        }
        return song_sheetVO;
    }


    @GetMapping("/SelectByPerson")
    @ApiOperation("查看指定用户的歌单")
    public Song_sheetVO SelectByPerson(@RequestParam @ApiParam(name = "person",value = "人员的id",required = true)Integer person){
         Song_sheetVO song_sheetVO = new Song_sheetVO();
         List<Song_sheet> song_sheets = song_sheetService.SelectByPerson(person);
         if(song_sheets.size()>0){
             song_sheetVO.setStatus(true);
             song_sheetVO.setData(song_sheets);
         }else{
             song_sheetVO.setStatus(false);
         }
         return song_sheetVO;
    }
}
